package dk.hojlind.hackhunt.control;

import java.util.ArrayList;

import dk.hojlind.hackhunt.model.ClientSocket;

public class PlayerHandler extends Handler{
	
	//Public variables
	
	//Private variables
	
	public PlayerHandler(String adress, int port)
	{
		super(adress, port);
	}
	
	public ArrayList<String> getActivePlayers()
	{
		String message = "getActivePlayers;";
		socket = new ClientSocket(adress, port);
		String response = socket.processRequest(message);
		ArrayList<String> players = playerArray(response);
		return players;
	}
	
	public ArrayList<String> playerArray(String toSort)
	{
		int start = 0;
		int end = 0;
		ArrayList<String> players = new ArrayList<String>();
		
		for(int i = 0; i < toSort.length(); i++)
		{
			if(toSort.charAt(i) == ';')
			{
				end = i;
				players.add(toSort.substring(start, end));
				start = i + 1;
			}
			if(i == toSort.length() - 1)
			{
				end = toSort.length();
				players.add(toSort.substring(start, end));
			}
		}
		
		return players;
		
	}

}
